import pandas as pd
import numpy as np

def view_results():
    """查看预测结果"""
    print("=== 查看预测结果 ===")
    
    try:
        # 读取结果文件
        results_df = pd.read_excel('3.xlsx')
        print(f"结果文件形状: {results_df.shape}")
        print(f"列名: {results_df.columns.tolist()}")
        print("\n预测结果预览:")
        print(results_df.head(10))
        
        print(f"\n预测结果统计:")
        if 'predicted_sales' in results_df.columns:
            print(results_df['predicted_sales'].describe())
            
            # 零销售统计
            zero_count = (results_df['predicted_sales'] == 0).sum()
            print(f"\n零销售预测数量: {zero_count}")
            print(f"零销售预测比例: {zero_count/len(results_df)*100:.1f}%")
            
            # 日期范围
            if 'finish_time' in results_df.columns:
                print(f"\n预测日期范围: {results_df['finish_time'].min()} 到 {results_df['finish_time'].max()}")
        
        # 检查是否有其他模型的预测结果
        pred_columns = [col for col in results_df.columns if col.startswith('pred_')]
        if pred_columns:
            print(f"\n包含 {len(pred_columns)} 个模型的预测结果:")
            for col in pred_columns:
                print(f"  {col}: 均值={results_df[col].mean():.2f}")
        
        return results_df
        
    except Exception as e:
        print(f"读取结果文件失败: {e}")
        return None

def compare_with_training_data():
    """对比训练数据和预测结果"""
    print("\n=== 对比训练数据和预测结果 ===")
    
    try:
        # 读取训练数据
        train_df = pd.read_excel('1.xlsx')
        results_df = pd.read_excel('3.xlsx')
        
        print("训练数据统计:")
        if 'value' in train_df.columns:
            train_stats = train_df['value'].describe()
            print(train_stats)
            
            # 非零销售统计
            non_zero_sales = train_df['value'][train_df['value'] > 0]
            if len(non_zero_sales) > 0:
                print(f"\n训练数据非零销售统计:")
                print(f"  非零销售数量: {len(non_zero_sales)}")
                print(f"  非零销售均值: {non_zero_sales.mean():.2f}")
                print(f"  非零销售标准差: {non_zero_sales.std():.2f}")
        
        print(f"\n预测数据统计:")
        if 'predicted_sales' in results_df.columns:
            pred_stats = results_df['predicted_sales'].describe()
            print(pred_stats)
        
        return train_df, results_df
        
    except Exception as e:
        print(f"对比数据失败: {e}")
        return None, None

if __name__ == "__main__":
    # 查看预测结果
    results_df = view_results()
    
    # 对比训练数据
    train_df, results_df = compare_with_training_data()
    
    print("\n=== 结果验证完成 ===")